package org.azmat.mybatis.Controller;

import org.azmat.mybatis.SQL.Service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class EmployeeController {

    @Autowired
    private EmployeeService employeeService;

    @GetMapping("/employee/{id}")
    public ModelAndView findEmployeeById(@PathVariable int id) {
        ModelAndView modelAndView = new ModelAndView("employeeById");
        modelAndView.addObject("employee", employeeService.findEmployeeById(id));
        return modelAndView;
    }

    @GetMapping("/employees/{id}")
    public ModelAndView findEmployeesById(@PathVariable int id) {
        ModelAndView modelAndView = new ModelAndView("employeesById");
        modelAndView.addObject("employees", employeeService.findLeaderAndEmployees(id));
        return modelAndView;
    }
}
